package com.zhilingshenghuo.app.zhly.view.widget;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.zhilingshenghuo.app.zhly.R;

public abstract class TipsPopWindow {

    private PopupWindow popupWindow;
    private Activity context;
    private int surplusNum;
    private int everydayNum;

    /**
     * 构造函数
     *
     * @param context
     */
    public TipsPopWindow(Activity context,int surplusNum,int everydayNum) {
        this.context = context;
        this.surplusNum = surplusNum;
        this.everydayNum = everydayNum;
    }

    /**
     * 显示警示框
     */
    @SuppressLint("SetTextI18n")
    public void show() {
        View popView = View.inflate(context, R.layout.pop_tips, null);
        popupWindow = new PopupWindow(context);
        popupWindow.setAnimationStyle(R.style.popWindow_animation);//设置动画
        popupWindow.setOutsideTouchable(true);
        popupWindow.setBackgroundDrawable(null);
        popupWindow.setFocusable(true);
        popupWindow.setContentView(popView);
        popupWindow.showAtLocation(context.getWindow().getDecorView(), Gravity.CENTER, 0, 0);

        TextView tvGoWatch = popView.findViewById(R.id.tvGoWatch);
        tvGoWatch.setText("免费金币 ("+surplusNum+"/"+everydayNum+")");

        LinearLayout llGoWatch = popView.findViewById(R.id.llGoWatch);
        llGoWatch.setOnClickListener(v -> goWatch());

        StrokeTextView tvGoExchange = popView.findViewById(R.id.tvGoExchange);
        tvGoExchange.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                exchange();
            }
        });
        popView.findViewById(R.id.ivClose).setOnClickListener(v -> popupWindow.dismiss());
        popupWindow.setOnDismissListener(() -> onDisMiss());
    }

    /**
     * 消失
     */
    public abstract void onDisMiss();

    /**
     * 看广告
     */
    public abstract void goWatch();

    /**
     * 去兑换
     */
    public abstract void exchange();

    public void disMiss(){
        popupWindow.dismiss();
    }
}
